Skip to content

aioble: Raise correct error if l2cap disconnects in middle of send.#1006

Merged
dpgeorge merged 1 commit intomicropython:masterfrom
andrewleech:aioble_l2cap_send_disconnect
Jun 24, 2025
Merged

aioble: Raise correct error if l2cap disconnects in middle of send.#1006
dpgeorge merged 1 commit intomicropython:masterfrom
andrewleech:aioble_l2cap_send_disconnect

Conversation

@andrewleech
Copy link
Copy Markdown
Contributor

When using aioble/l2cap to send data from micropython to a cental like a phone, if the ble disconnects in the middle of a send process it can currently fail with the exception:

Traceback (most recent call last):
  File "aioble/l2cap.py", line 147, in send
TypeError: can't convert NoneType to int

This is because the send function is operating in a loop sending the data in chunks.
At the top of the function self._assert_connected() is already called which will raise a L2CAPDisconnectedError if the connection has already been dropped (as detected by self._cid is None however the chunk send loop can run for some time, a disconnect in the middle of this results in self._cid = None being passed to ble.l2cap_send() resulting in the exception above.

This PR simply adds the correct connection check immediately before each loop of l2cap_send().

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants